package top.kaoshanji.r4ch12b;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 代码清单-r4ch12b-398页a：一个POJO完成所有功能，既是Controller，又是Service，还是DAO
 * @author kaoshanji
 * ^_^
 * create time 2025/5/9 17:54
 */
@Controller
public class MixLayerUserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @RequestMapping(value = "/logon.do", method = RequestMethod.GET)
    @Transactional
    public String logon(String userName, String passWord) {
        if (isRightUser(userName, passWord)) {
            String sql = " UPDATE t_user1 u SET u.score = u.score + ? WHERE user_name =? ";
            jdbcTemplate.update(sql,20,userName);
            return "success";
        } else {
            return "fail";
        }
    }

    private boolean isRightUser(String userName,String password) {
        return true;
    }

}
